package com.wn.controller;

import com.wn.bean.House;
import com.wn.bean.HouseQueryDto;
import com.wn.bean.PageVo;
import com.wn.bean.Result;
import com.wn.service.IHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

/**
 * @author yellow Docter
 * @date 2024-07-02
 * @desc 蜗牛创想：www.woniuxy.com
 */
@RestController
@RequestMapping("/house")
public class HouseController {

    @Autowired
    private IHouseService houseService;

    @GetMapping("/{currentPage}/{pageSize}")
    public Result<PageVo> listAll(@PathVariable("currentPage")int currentPage,
                                  @PathVariable("pageSize")int pageSize, HouseQueryDto houseQueryDto){
        PageVo pageVo = houseService.getHouseList(currentPage,pageSize,houseQueryDto);
        return Result.ok(pageVo);
    }

    @PostMapping
    public Result<String> addHouse(@RequestBody House house){
        //设置默认值
        house.setCreateTime(LocalDate.now());
        house.setLastUpdateTime(LocalDate.now());
        boolean flag = houseService.addHouse(house);
        return flag ? Result.ok() : Result.fail();
    }

}
